<?php
    include("../service/bannerService.php");
    include("../service/imageService.php");
    
    $imagePath = "../img/banner/";
    $bannerImg = $_FILES["bannerImg"];
    $proID = $_POST["products"] == "" ? "NULL" : $_POST["products"];
    
    $actionResult = addBanner($proID, $imagePath.$bannerImg['name']);
    
    if($actionResult) {
        if(!is_dir($imagePath)) mkdir($imagePath);
        $result = move_uploaded_file($bannerImg["tmp_name"], $imagePath.$bannerImg['name']);
        
        if($result > 0)
            echo "<script>window.location = '../admin-page/banner.php?actionResult=ok'</script>";
        else
            echo "<script>window.location = '../admin-page/banner.php?actionResult=no'</script>";
    } else {
        echo "<script>window.location = '../admin-page/banner.php?actionResult=no'</script>";
    }
    
?>
